<template>
  <div class="app-container">
      <el-tabs v-model="activeName" type="card"  >
          <el-tab-pane label="平台配置" name="first">
          <el-form ref="sysConfig" :model="sysConfig" label-width="120px">
            <!-- <el-form-item label="通知方式">
                <el-row>
                  <el-checkbox-group v-model="checks">
                    <el-checkbox v-for="(item,index) in checkList" :key="item.value" :label="item.name" :value="item.value" ></el-checkbox>
                  </el-checkbox-group>
                </el-row>
            </el-form-item> -->
            <el-form-item label="跟进提醒">
                <el-row>
                    <el-input-number  v-model="sysConfig.visitLimt"  :min="0" :max="100" ></el-input-number>
                </el-row>
                <el-row>
                    <span class="tip">跟进前N天提醒客户经理</span>
                </el-row>
            </el-form-item>
            <el-form-item label="合同到期提醒">
                <el-row>
                    <el-input-number  v-model="sysConfig.contractLimt"  :min="0" :max="100" ></el-input-number>
                </el-row>
                <el-row>
                    <span class="tip">合同到期前N天提醒客户经理</span>
                </el-row>
            </el-form-item>
            <el-form-item label="客服电话"   >
                <el-row  style="width:200px;">
                    <el-input placeholder="请输入客服电话" v-model="sysConfig.tel" ></el-input>
                </el-row>
            </el-form-item>
            <div class="line"></div>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit1">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
        
        <el-tab-pane label="公海规则配置" name="second">
          <el-form ref="customerConfig" :model="customerConfig" label-width="120px">
             
            <el-form-item label="认领频率规则">
                <el-row>
                    <el-input-number  v-model="customerConfig.rlLimit"  :min="0" :max="100" ></el-input-number>
                </el-row>
                <el-row>
                    <span class="tip">每天最多认领N个客户,0为不限制</span>
                </el-row>
            </el-form-item>
            <el-form-item label="提醒规则">
               
               <el-row>
                    <el-input-number v-model="customerConfig.txLimit"   :min="0" :max="100" ></el-input-number>
                </el-row>
                <el-row>
                    <span class="tip">认领到期提前N天提醒负责人，0为不提醒</span>
                </el-row>
            </el-form-item>
            <el-form-item label="回收规则" >
               <el-row>
                    <el-input-number v-model="customerConfig.hsLimit"  :min="0" :max="100" ></el-input-number>
                </el-row>
                <el-row>
                    <span class="tip">超过N天未成交客户自动进入公海，0为不限制</span>
                </el-row>
            </el-form-item>
            <div class="line"></div>
            <div style="float:right;margin-right:20px">
              <el-button type="primary" @click="onSubmit2">提交</el-button>
            </div>
          </el-form>
        </el-tab-pane>
       
      </el-tabs>
  </div>
</template>

<script>
 import { getConfig,editConfig } from "@/api/crm/config";

export default {
  name: "config",
  data() {
    return {
      checks:[],
      checkList: [{"name":"短信","value":1},{"name":"邮件","value":2},{"name":"微信消息","value":3}],
      activeName: 'first',
      customerConfig:{
          rlLimit: 1,
          txLimit: 1,
          hsLimit: 1
      },
      sysConfig:{
          tel:undefined,
          noticeType:undefined,
          visitLim:undefined,
          contractLimt:undefined
      },
    
    };
  },
  created() {
      this.getConfig();
  },
  mounted() {
   
  },
  methods: {
    getConfig(){
        getConfig().then((response) => {
            this.sysConfig=JSON.parse(response.sysConfig);
            // var checkIds=this.sysConfig.noticeType.split(",");
            // this.checks=[];
            // for(var k=0;k<this.checkList.length;k++){
            //   for(var j=0;j<checkIds.length;j++){
            //       if(checkIds[j]==this.checkList[k].value){
            //         this.checks.push(this.checkList[k].name);
            //       }
            //   }
            // }
            this.customerConfig=JSON.parse(response.customerConfig);
        });
    },
    onSubmit1() {
      
      // var noticeIds=[];
      // console.log(this.checks);
      // console.log(this.checkList);
      // for(var i=0;i<this.checks.length;i++){
      //     for(var k=0;k<this.checkList.length;k++){
      //       if(this.checks[i]==this.checkList[k].name){
      //         noticeIds.push(this.checkList[k].value);
      //       }
      //     }
      // }
      // console.log(noticeIds);
      // this.sysConfig.noticeType=noticeIds.toString();
      var data={configKey:"sys:config",configValue:JSON.stringify(this.sysConfig)}
      editConfig(data).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfig();
        }
      });
    },
    onSubmit2() {
      var data={configKey:"customer:config",configValue:JSON.stringify(this.customerConfig)}
      editConfig(data).then(response => {
        if (response.code === 200) {
          this.msgSuccess("修改成功");
          this.getConfig();
        }
      });
    }
     
  }
};
</script>
<style scoped lang="scss">
.tip{
  color:indianred;
}
.line{
  margin: 10px 0;
  background-color:gainsboro;
  height:1px;
}
.el-row {
  margin-bottom: 0px;
  &:last-child {
    margin-bottom: 0;
  }
}
</style>
 
